<!doctype html>
<html lang="zh">
<head>
  <meta charset="UTF-8">
  <meta name="viewport"
        content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>电影</title>
<style>
body{
  margin: 0;
  font-size: 15px;
}
.title{
  display: inline-block;
  width: 20%;
  text-align: center;
  height: 26px;
  line-height: 26px;
  -webkit-tap-highlight-color:rgba(255,0,0,0);
}
.title-active{
  color: red;
}
.books{
  display: flex;
  border-bottom: 1px solid rgba(0,0,0,.1);
  padding: 12px 16px;
  position: relative;
}
.books>img{
  margin-right: 16px;
  height: 120px;
}
.book-date{
  display: flex;
  justify-content: space-between;
}
.book-right{
  width: calc(100% - 106px);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.head {
  display: flex;
  position: relative;
  width: 100%;
  background: #fff;
  height: 40px;
  line-height: 40px;
  border-bottom: 1px solid rgba(0,0,0,.1);
}
.head>div{
  flex: 1;
  text-align: center;
}
.tab-active{
  background-color: #dd001b;
  position: absolute;
  width: 30px;
  height: 2px;
  bottom: 0;
  left: 78px;
  transition: left .3s ease-out;
}
.small-font{
  font-size: 13px;
}
.inputcover{
  background: #ebecec;
  border-radius: 30px;
  padding-left: 14px;
  margin: 15px 10px;
}
.input{
  height: 30px;
  line-height: 18px;
  border: none;
  background: transparent;
  outline: none;
  padding: 0;
  -webkit-tap-highlight-color:rgba(255,0,0,0);
  width: 80%;
}
.icon{
  vertical-align: text-bottom;
  padding-right: 4px;
}
.load-more{
  height: 50px;
  border: 1px solid rgba(0,0,0,.1);
  border-radius: 5px;
  text-align: center;
  line-height: 50px;
  margin: 10px;
}
</style>
</head>
<body>
<div id="app">
  <div class="head">
    <div onclick="changeTab(0)">分类</div>
    <div onclick="changeTab(1)">播放</div>
    <div class="tab-active" style="left: 79px;"></div>
  </div>
  <div class="list-box" style="height: calc(100vh - 41px);overflow-y: auto;overflow-x: hidden;">
  <div class="inputcover">
    <svg t="1573973499123" style="vertical-align: middle;" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="24623" width="14" height="14"><path d="M998.417847 968.923523 738.389131 712.967573c68.050929-73.967263 109.909294-171.800228 109.909294-279.479317 0-230.345352-189.746575-417.036095-423.778057-417.036095-234.030475 0-423.77705 186.690742-423.77705 417.036095 0 230.297023 189.746575 416.986758 423.77705 416.986758 101.131452 0 193.870691-34.971414 266.723355-93.126882l261.095991 256.924553c12.70864 12.514315 33.370499 12.514315 46.078132 0C1011.174816 1001.759377 1011.174816 981.436831 998.417847 968.923523L998.417847 968.923523 998.417847 968.923523zM424.520368 786.354882c-198.040115 0-358.5393-157.977996-358.5393-352.86562 0-194.88863 160.499184-352.866627 358.5393-352.866627C622.562497 80.622635 783.110011 238.600632 783.110011 433.489262 783.110011 628.376886 622.562497 786.354882 424.520368 786.354882L424.520368 786.354882 424.520368 786.354882z" p-id="24624" fill="#333333"></path></svg>
    <input type="text" class="input" value="swag" onkeydown="keydown(event)" placeholder="搜索">
  </div>
  <div id="videoList"></div>
  <div class="load-more" onclick="getList()">加载更多</div>
  </div>
  <div class="play-box" style="display: none;">
    <video id="video" preload="auto" webkit-playsinline="true" playsinline
           x5-playsinline="true" x-webkit-airplay="true" controls style="width: 100%;"></video>
  </div>
</div>
<script>
// scp -P 29242 Desktop\nginx-1.18.0\html\fandeng.html root@65.49.222.36:/usr/local/nginx/html/index.html
var leftWidth=188,pageNumber=1
document.cookie='bs=ud36tzqujga1oqj2e93ygyo387t58nor'
document.cookie='platform=mobile'
// window.addEventListener('resize',()=>{
//   this.leftWidth=document.body.clientWidth/2
// })
leftWidth=document.body.clientWidth/2
if(leftWidth > 200){
  leftWidth-=5.5
}
getList(1)
changeTab(0)
function $(el){
  return document.querySelector(el)
}
function keydown(e){
  if(e.keyCode===13){
    getList(1)
  }
}
function changeTab(flag){
  $('.tab-active').style.left=((flag*2+1)*leftWidth-30)/2+'px'
  $('.list-box').style.display=flag?'none':'block'
  $('.play-box').style.display=flag?'block':'none'
}
function play(id){
  fetch('/view_video.php?viewkey='+id).then(v=>v.text()).then(_=>{
    var index = _.indexOf('get_media')
    var key = _.slice(index+12,_.indexOf('&',index+12))
    fetch('/video/get_media?e=0&t=p&v='+id+'&s='+key).then(v=>v.json()).then(_=>{
      var item = _.find(v=>v.quality==='720')
      if(!item){
        item = _.find(v=>v.defaultQuality)
      }
      changeTab(1)
      $('#video').src='/videos'+item.videoUrl.slice(7)
    })
  })
}
function getList(flag){
  var keyword=$('.input').value
  if(keyword.trim()===''){
    return
  }
  if(flag===1){
    pageNumber=1
  }else{
    pageNumber++
  }
  fetch('/video/search?search='+keyword+'&page='+pageNumber).then(v=>v.text()).then(_=>{
    var list=[]
    var index=0
    var index1=_.indexOf('data-video-vkey')
    while(index1!==-1){
        var index2=_.indexOf('data-src',index1)
        var index3=_.indexOf('alt',index2)
        var index4=_.indexOf('class="time"',index3)
        var obj={
            videoSrc:_.slice(index1+17,_.indexOf('"',index1+17)),
            img:'/videos'+_.slice(index2+19,_.indexOf('"',index2+19)),
            title:_.slice(index3+5,_.indexOf('"',index3+5)),
            time:_.slice(index4+13,_.indexOf('<',index4+13))
        }
        list.push(obj)
        index=index3
        index1=_.indexOf('data-video-vkey',index)
    }
    var str = ''
    list.forEach(_=>{
      str+=`<div onclick="play('${_.videoSrc}')" class="books">
        <img src="${_.img}">
        <div class="book-right">
          <div>
            <div>${_.title}</div>
          </div>
          <div class="book-date">
            <div></div>
            <div class="small-font">${_.time}</div>
          </div>
        </div>
      </div>`
    })
    if(flag===1){
      $('#videoList').innerHTML=str
    }else{
      $('#videoList').innerHTML+=str
      // $('#videoList').insertAdjacentHTML('beforeend',str)
    }
  })
}
</script>
</body>
</html>